package mode.strategy;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 支付策略上下文
 *
 * @author xjx
 * @date 2023/7/31 10:19
 */
public class PaymentStrategy {

    private static Map<String, Pay> payServiceMap = new ConcurrentHashMap<>();

    static {
        payServiceMap.put("cash", new Cash());
        payServiceMap.put("weChat", new WeChatPay());
        payServiceMap.put("Ali", new AliPay());
    }

    //获取指定策略实现接口
    public static Pay getPayService(String payment) {
        return payServiceMap.get(payment) == null ? new Cash() : payServiceMap.get(payment);
    }
}
